// pages/mine/mine.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    username: getApp().globalData.username,
    img: getApp().globalData.img,
    unreadNum: 19,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(getApp().globalData.username)
    this.setData({
      username: getApp().globalData.username
    })
    this.getInfo()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log(getApp().globalData.username)
    this.setData({
      username: getApp().globalData.username
    })
    this.getInfo();
    this.enterPage(8);
    console.log(8)
  },

  /**
   * 进入医生端 mine页面，通知后端将进入此页面次数加一
   */
  enterPage: function (e) {
    var that = this
    wx.request({
      url: getApp().globalData.url + 'patientsettablebar',
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        unitphone: getApp().globalData.username,
        pageNum: e
      },
    })
  },

   /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getInfo()
  },

  /**
   * 设置个人信息
   */
  selfSetUp: function(){
    wx.navigateTo({
      url: '../setup/setup',
    })
  },

  /**
   * 查看我的通知
   */
  viewMyInfo: function(){
    wx.navigateTo({
      url: '../myInfo/myInfo',
    })
  },

  /**
   * 是否有未读消息
   */
  getInfo: function(){
    var that = this
    wx.request({
      url:  getApp().globalData.url+'getSelfInfo',
      method: 'GET',
      data: {
        username: getApp().globalData.username
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {
        that.setData({
          img: res.data.logoLink,
          unreadNum: res.data.unreadNumber,
        })
      },
      fail(res) {
        wx.showToast({
          title: '获取未读消息失败，请从顶部下拉刷新',
          icon: 'none',
          duration: 2000
        })
      }
    })
  },

  /**
   * 设置预约时间
   */
  appointmentSettingBtnClick:function(){
    wx.navigateTo({
      url: '../setAppointment/setAppointment',
    })
  },

  assistantSettingBtnClick:function(){
    wx.navigateTo({
      url: '../assistantList/assistantList',
    })
  },

  qualifictionSettingBtnClick:function(){

  },

  /**
   * 用户退出登录
   */
  exitLogin: function(){
    wx.showModal({
      title: '退出',
      content: '确定退出吗？',
      success: function(sm) {
        if (sm.confirm) {
          try {
            wx.clearStorageSync()
          } catch (e) {
            // Do something when catch error
          }
          wx.clearStorage()
          wx.reLaunch({
           url: "../login/login",
          })
          
        } else if (sm.cancel) {
        }
      }
    })
  },
})